import java.util.*;


public class Solution5 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * longest common substring
     * @param str1 string字符串 the string
     * @param str2 string字符串 the string
     * @return string字符串
     */
    public String LCS (String str1, String str2) {
        // write code here
        char[] c1 = str1.toCharArray();
        char[] c2 = str2.toCharArray();
        int index = 0;
        int len = 0;
        int[][] dp = new int[c1.length][c2.length];
        for(int i = 0;i<c1.length;i++) {
            for(int j = 0;j<c2.length;j++) {
                if(i > 0 && j > 0 && c1[i] == c2[j]) {
                    dp[i][j] = dp[i-1][j-1] + 1;
                } else {
                    if(c1[i] == c2[j]) {
                        dp[i][j]++;
                    }
                }
                if(len < dp[i][j]) {
                    len = Math.max(len,dp[i][j]);
                    index = i;
                }
            }
        }
        return str1.substring(index - len + 1,index + 1);
    }
}